package query

type MultiMatch struct {
	Fields             []string    `json:"fields"`
	Query              interface{} `json:"query"`
	Type               string      `json:"type"`                 //  类型 "best_fields"(default), "most_fields", "cross_fields", "phrase", "phrase_prefix", "bool_prefix"
	Fuzziness          string      `json:"fuzziness"`            //  Levenshtein编辑距离 "AUTO"(default), "0", "1", "2"
	MinimumShouldMatch string      `json:"minimum_should_match"` //  should条件必须至少满足多少个
	Operator           string      `json:"operator"`             // "OR"(default), "AND"
}

func (g *MultiMatch) Empty() bool {
	return g == nil || len(g.Fields) == 0 || IsAnyEmpty(g.Query)
}

func (g *MultiMatch) Map() Map {
	vm := Map{
		"fields": g.Fields,
		"query":  g.Query,
	}
	if g.Type != "" {
		vm["type"] = g.Type
	}
	if g.Fuzziness != "" {
		vm["fuzziness"] = g.Fuzziness
	}
	if g.MinimumShouldMatch != "" {
		vm["minimum_should_match"] = g.MinimumShouldMatch
	}
	if g.Operator != "" {
		vm["operator"] = g.Operator
	}

	return Map{
		"multi_match": vm,
	}
}

/*
func _MultiMatch[T any](keys []string, value T, fuzz, minRate, operator string) map[string]interface{} {
	if _, ie := _IsAnyEmpty(value); ie {
		return nil
	}
	multiMatchQuery := map[string]interface{}{
		"multi_match": map[string]interface{}{
			"query":                value,
			"fields":               keys,
			"fuzziness":            fuzz,
			"minimum_should_match": minRate,
			"operator":             operator,
		},
	}
	return multiMatchQuery
}

*/
